<template>
	<view>


		<view class="header" @click="goBack">
			<view class="">
				<text class="cuIcon-back"></text>
			</view>
			<view class="title">
				<text style="color: #000000;">出库商品</text>
			</view>
		</view>



		<!-- <view class="VerticalBox">
			<scroll-view class="VerticalNav nav" scroll-y scroll-with-animation :scroll-top="verticalNavTop" style="height:calc(100vh)">
				<view class="cu-item" :class="index == tabCur ? 'text-green cur' : ''" v-for="(item, index) in list" :key="index"
				 @tap="TabSelect" :data-id="index" v-if="item.goods.length > 0">
					{{ item.name }}
				</view>
			</scroll-view>
			<scroll-view class="VerticalMain" scroll-y scroll-with-animation style="height:calc(100vh)" :scroll-into-view="'main-' + mainCur"
			 @scroll="VerticalMain">
				<view class="padding-top padding-lr" v-for="(item, index) in list" :key="index" :id="'main-' + index">
					<view class="cu-bar solid-bottom bg-white" v-if="item.goods.length > 0">
						<view class="action">
							<text class="cuIcon-title text-green"></text>
							{{ item.name }}
						</view>
					</view>
					<block v-for="(item1, id) in item.goods" :key="id" >
						<block v-if="item1.num > 0">
							<view class="cu-list menu-avatar" @click="inputNum(item1)">
								<view class="cu-item">
									<view class="cu-avatar round lg" style="width: 100rpx; height: 100rpx;border-radius: 50rpx;">
										<image :src="item1.image" mode=""></image>
									</view>
									<view class="content flex-direction">
										<text>{{item1.name}}</text>
										<view class="">
											<text>库存: </text>
											<view class="cu-tag round bg-gradual-orange sm">{{item1.num}}</view>
										</view>
									</view>
								</view>
							</view>
						</block>
					</block>
				</view>
			</scroll-view>
		</view> -->





		<view class="text-tab">
			<view class="box">
				<view class="marige-bor" v-for="(item, index) in list" :key="index">
					<view class="diso-flex" @click="inputNum(item)">
						<view class="left-box">
							<view class="left-box-image">
								<image class="" :src="img + item.image" mode=""></image>
							</view>
							<!-- {{img + item.image}} -->
							<view class="" style="line-height: 60rpx;">
								<view class="">
									{{item.name}}
								</view>
								<view class="">
									库存: &nbsp{{item.stock_num}} {{item.unit_name}}
								</view>
							</view>
						</view>
						<!-- <view class="">
							11111
						</view> -->
					</view>
				</view>
			</view>
		</view>








		<u-popup v-model="show" mode="center" width="500rpx" height="160px" border-radius="20">
			<view class="show" style="height: 60rpx; line-height: 60rpx; padding-top: 20rpx;">
				{{textName}}
			</view>
			<view class="show-poup flex-box">
				<text>数量</text>
				<input type="number" v-model="num" placeholder="请输入" />
			</view>
			<view class="flex-around add-clas">
				<view class="" style="background-color: #CCCCCC;" @click="show = false">
					取消
				</view>
				<view class="bg-gradual-blue" @click="addInpput">
					确定
				</view>
			</view>
		</u-popup>







	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				tabCur: 0,
				mainCur: 0,
				verticalNavTop: 0,
				load: true,
				show: false,
				memo: '',
				num: '',
				stockId: '',
				goodsList: [],
				inofId: '',
				itemName: '',
				textName: '',
				listLength: '',
				img: this.$images,
			};
		},
		// onReady() {
		// 	uni.hideLoading();
		// },
		onLoad(e) {
			this.stockId = e.stock
			console.log(e.stoc == undefined)
			this.stockInfoId = e.stockId
			this.getList()
		},
		methods: {

			addInpput() {
				if (this.num == '') return this.$tools.msg('输入的数量不能为空')
				this.show = false
				var obj = {
					num: this.num,
					goods_id: this.inofId,
					name: this.itemName.name,
					image: this.itemName.image,
					unit: this.itemName.unit_name,
				}

				this.$tools.msg('成功！')
				
				console.log('this.this.itemName',this.itemName)
				
				this.goodsList.push(obj)
				console.log('this.goodsList',this.goodsList)
				uni.setStorageSync('addStorckList', this.goodsList)
			},


			inputNum(item) {
				console.log(item)
				this.memo = ''
				this.num = ''
				this.show = true
				this.inofId = item.goods_id
				this.itemName = item
				this.textName = item.name
				console.log(item)
			},


			goBack(id) {

				console.log(id)


				// let pages = getCurrentPages(); //获取所有页面栈实例列表
				// let nowPage = pages[pages.length - 1]; //当前页页面实例
				// let prevPage = pages[pages.length - 2]; //上一页页面实例
				// // prevPage.$vm.godList = JSON.stringify(this.goodsList);
				// prevPage.$vm.listFrom = this.goodsList  //修改上一页data里面的searchVal参数值为1211
				// // prevPage.$vm.godList = this.goodsList
				// console.log('this.goodsList',this.goodsList)

				uni.navigateBack({
					url: '/pages/putStock/addShop?navigatorProp=' + 4
				})

			},

			// 获取;列表
			async getList() {
				const res = await this.$u.post("api/Invoic/store_info", {
					store_id: this.stockInfoId
				});
				this.list = res.data
				this.listLength = this.list.length
				console.log('this.listLength', this.list)
			},





			TabSelect(e) {
				this.tabCur = e.currentTarget.dataset.id;
				this.mainCur = e.currentTarget.dataset.id;
				this.verticalNavTop = (e.currentTarget.dataset.id - 1) * 50;
			},
			VerticalMain(e) {
				// #ifdef MP-ALIPAY
				return false; //支付宝小程序暂时不支持双向联动
				// #endif
				let that = this;
				let tabHeight = 0;
				if (this.load) {
					for (let i = 0; i < this.list.length; i++) {
						let view = uni.createSelectorQuery().select('#main-' + this.list[i].id);
						view.fields({
								size: true,
							},
							data => {
								this.list[i].top = tabHeight;
								// tabHeight = tabHeight + data.height;
								// this.list[i].bottom = tabHeight;
							},
						).exec();
					}
					this.load = false;
				}
				let scrollTop = e.detail.scrollTop + 10;
				for (let i = 0; i < this.list.length; i++) {
					if (scrollTop > this.list[i].top && scrollTop < this.list[i].bottom) {
						this.verticalNavTop = (this.list[i].id - 1) * 50;
						this.tabCur = this.list[i].id;
						console.log(scrollTop);
						return false;
					}
				}
			},
		},
	};
</script>

<style lang="scss" scoped>
	.text-tab {
		width: 100%;
		padding: 30rpx;
		padding-bottom: 0;
		background-color: #EEEEEE;


		.box {
			width: 98%;
			margin: 0 auto;
			background-color: #FFFFFF;
			border-radius: 10rpx;
		}

		.marige-bor {
			width: 90%;
			margin: 0 auto;
			color: #333333;
			display: flex;
			font-size: 28rpx;
			padding: 20rpx 0;
			align-items: center;
			// border-bottom: 1rpx solid #F0F0F0;
			justify-content: space-between;

			.diso-flex {
				width: 100%;
				display: flex;
				align-items: center;
				padding-bottom: 20rpx;
				justify-content: space-between;
				border-bottom: 1rpx solid #EEEEEE;


				.left-box {
					display: flex;
					align-items: center;

					.left-box-image {
						width: 220rpx;
						height: 220rpx;
						margin-right: 22rpx;
						border-radius: 10rpx;

						image {
							width: 220rpx;
							height: 220rpx;
						}
					}

					.box-border {
						width: 100%;
						height: 100%;
						line-height: 60rpx;
						align-items: center;
					}
				}

				.right-box {
					width: 100%;
					height: 158rpx;
					display: flex;
					align-items: center;
					justify-content: space-between;
					border-bottom: 1rpx solid #F0F0F0;
				}

			}

			.conter-image {
				width: 22rpx;
				height: 36rpx;
			}
		}
	}


	.header {
		width: 100%;
		height: 150rpx;
		padding-left: 20rpx;
		line-height: 150rpx;
		display: flex;
		align-items: center;
		// padding-left: 10rpx;
		padding-top: 30rpx;
		font-size: 36rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #000000;
		background: #EEEEEE;

		.arrow {
			position: relative;
			display: inline-block;
		}

		.arrow::before {
			content: '';
			width: 10px;
			height: 10px;
			border: 0px;
			border-bottom: solid 2px #fff;
			border-left: solid 2px #fff;
			-ms-transform: rotate(45deg);
			-webkit-transform: rotate(45deg);
			transform: rotate(45deg);
			position: absolute;
			top: 50%;
			left: 0;
			margin-top: -4px;
			margin-left: 28rpx;
		}

		.title {
			color: #fff;
			margin: 0 auto;
		}
	}





	.fixed {
		position: fixed;
		z-index: 99;
	}

	.VerticalNav.nav {
		width: 200upx;
		white-space: initial;
	}

	.VerticalNav.nav .cu-item {
		width: 100%;
		text-align: center;
		background-color: #fff;
		margin: 0;
		border: none;
		height: 50px;
		position: relative;
	}

	.VerticalNav.nav .cu-item.cur {
		background-color: #f1f1f1;
	}

	.VerticalNav.nav .cu-item.cur::after {
		content: '';
		width: 8upx;
		height: 30upx;
		border-radius: 10upx 0 0 10upx;
		position: absolute;
		background-color: currentColor;
		top: 0;
		right: 0upx;
		bottom: 0;
		margin: auto;
	}

	.VerticalBox {
		display: flex;
	}

	.VerticalMain {
		background-color: #f1f1f1;
		flex: 1;
	}


	.show-poup {
		width: 80%;
		height: 70rpx;
		line-height: 70rpx;
		border-radius: 10rpx;
		margin: 36rpx auto;
		padding-left: 30rpx;
		background-color: #F5F5F5;
	}

	.add-clas {
		width: 100%;
		height: 60rpx;

		view {
			width: 30%;
			height: 60rpx;
			color: #FFFFFF;
			line-height: 60rpx;
			border-radius: 30rpx;
			text-align: center;
		}
	}
</style>
